﻿Ext.ns('suce.informe');

suce.informe.view = function (config) {
    return new Ext.Window(Ext.apply({
        title: 'Visualizador de informes',
        height: 300,
        width: 400,
        idsolicitud: null,
        idversion: null,
        initComponent: function () {
            var me = this;
            me.bbar = [{ text: 'Guardar', handler: me.ver, scope: me}];
            me.gridReportes = new Ext.grid.Panel({
                title: 'Reportes',
                //store: STORE('mant.ashx', { C: 'consulta', S: 'reportes', solicitud: this.idsolicitud, version: this.idversion }, 'nroinforme,formato,suce'),
                store: SIMPLESTORE([], 'nroinforme,formato,suce'),
                /*columns: COLMODEL([
                ['nroinforme', 'Informe', 0.3, { align: 'center'}],
                ['formato', 'Formato', 0.3, { align: 'center'}],
                ['suce', 'Nro de SUCE', 0.4, { align: 'center'}],
                [{ xtype: 'actioncolumn', width:50, items: [{ iconCls: 'tb-pdf', tooltip: 'Ver documento', handler : function (grid, rowIndex, colIndex){
                        
                }}]}]
                ])*/
                columns: [
                    { text: 'Informe', dataIndex: 'nroinforme', flex: 2 },
                    { text: 'Formato', dataIndex: 'formato', flex: 2 },
                    { text: 'Nro de SUCE', dataIndex: 'suce', flex: 2 },
                    { xtype: 'actioncolumn', flex: 1, align : 'center', items: [
                        { icon: 'ext/images/icons/pdf.gif', tooltip: 'Ver documento',scope: me, handler: function (grid, rowIndex, colIndex) {
                            //var me = this;
                            var record=grid.getStore().getAt(rowIndex);
                            var url = 'reporte.aspx?' + Ext.urlEncode({ solicitud: me.idsolicitud, version: me.idversion, nroreporte: record.get('nroinforme')});
                            //console.log(me.idsolicitud, me.idversion);
                            MyApp.openWindow(url);
                        }
                        }]
                    }
                ]
            });
            //console.log(me.idsolicitud, me.idversion);
            me.items = [me.gridReportes];

            Ext.Window.prototype.initComponent.call(me);
        },
        ver: function () {
            var me = this;
            var url = 'reporte.aspx?' + Ext.urlEncode({ solicitud: me.idsolicitud, version: me.idversion });
            console.log(me.idsolicitud, me.idversion);
            MyApp.openWindow(url);
        },
        show: function (p) {
            var me = this;
            me.idsolicitud = p.idsolicitud;
            me.idversion = p.idversion;
            callServer('mant.ashx', { C: 'REPORTES', S: 'CONSULTA', idsolicitud: me.idsolicitud, idversion: me.idversion }, function (v) {
                v = Ext.decode(v);
                me.gridReportes.store.loadData(v);
            }, me);
            Ext.Window.prototype.show.call(me);
        }
    }, config));
}

